/**
 * Created by Amaris on 2016/10/9.
 */

var Waterline = require('waterline');
var uuid = require('node-uuid');
var moment = require('moment');

/**
 * 行业组合仓位表
 */
module.exports = Waterline.Collection.extend({
    identity: 'stock_position',
    tableName: 'tb_stock_position',
    connection: "mysql",
    attributes: {

        rowId: {
            type: 'string',
            primaryKey: true,
            unique: true,
            required: true,
            uuidv4: true,
            columnName: 'rowId',
            defaultsTo: function () {
                return uuid.v4();
            }
        },
        stockGroupId: {
            type: 'string',
            required: true,
            columnName: 'stockGroupId',
            model:'stock_group'
        },
        name: {
            type: 'string',
            columnName: 'name',
        },
        content: {
            type: 'string',
            columnName: 'content',
        },
        price: {
            type: 'float',
            required: true,
            columnName: 'price',
        },
        balance: {
            type: 'float',
            required: true,
            columnName: 'balance',
        },
        createUid: {
            type: 'string',
            required: true,
            columnName: 'createUid',
            model: 'user'
        },
        updatedAt: {
            type: 'string',
            columnName: 'updatedAt'
        },
        /**
         *是否删除，1表示正常默认为1，0表示删除
         */
        // enable: {
        //     type: 'string',
        //     columnName: 'enable',
        //     defaultsTo:'1'
        // },
        createdAt: {
            type: 'string',
            required: true,
            columnName: 'createdAt'
        },
        toJSON: function () {
            var obj = this.toObject();
            obj.createdAt = moment(obj.createdAt).format('YYYY/MM/DD hh:mm');
            obj.updatedAt = moment(obj.updatedAt).format('YYYY/MM/DD hh:mm');
            return obj;
        }

    }
});
